package cn.gaily.eduservice.controller.front;

import cn.gaily.commonutils.R;
import cn.gaily.eduservice.entity.EduCourse;
import cn.gaily.eduservice.entity.EduTeacher;
import cn.gaily.eduservice.service.EduCourseService;
import cn.gaily.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(description = "前端显示数据接口")
@RestController
@RequestMapping("/eduservice/indexfront")
@CrossOrigin
public class IndexFrontController {

    @Autowired
    private EduCourseService eduCourseService;
    @Autowired
    private EduTeacherService eduTeacherService;


    @ApiOperation("查询前4个热门课程，前8名热门老师")
    @GetMapping("/index")
    public R index(){
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 4");
        List<EduCourse> courseList = eduCourseService.list(wrapper);


        QueryWrapper<EduTeacher> teacherWrapper = new QueryWrapper<>();
        teacherWrapper.orderByDesc("id");
        teacherWrapper.last("limit 8");
        List<EduTeacher> teacherList = eduTeacherService.list(teacherWrapper);

        return R.ok().data("eduList",courseList).data("teacherList",teacherList);
    }
}
